﻿using BDPAutodetect.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BDPAutodetect.Client
{
    /// <summary>
    /// TargetDetectView.xaml 的交互逻辑
    /// </summary>
    [ObservableObject]
    public partial class TargetDetectView : UserControl
    {
        /// <summary>
        /// 填充检测状态画刷颜色
        /// </summary>
        [ObservableProperty]
        protected Brush detectBackgroundColor = new SolidColorBrush(Colors.White);
        /// <summary>
        /// 填充检测结果状态画刷颜色
        /// </summary>
        [ObservableProperty]
        protected Brush detectResultBackgroundColor = new SolidColorBrush(Colors.White);

        /// <summary>
        /// 信号颜色
        /// </summary>
        public System.Drawing.Color DetectColor { get { return (System.Drawing.Color)GetValue(DetectColorProperty); } set { SetValue(DetectColorProperty, value); } }
        /// <summary>
        /// 信号颜色属性
        /// </summary>
        public static readonly DependencyProperty DetectColorProperty = DependencyProperty.Register("DetectColor", typeof(System.Drawing.Color), typeof(TargetDetectView), new FrameworkPropertyMetadata(System.Drawing.Color.White, FrameworkPropertyMetadataOptions.AffectsRender));

        /// <summary>
        /// 信号颜色
        /// </summary>
        public System.Drawing.Color DetectResultColor { get { return (System.Drawing.Color)GetValue(DetectResultColorProperty); } set { SetValue(DetectResultColorProperty, value); } }
        /// <summary>
        /// 信号颜色属性
        /// </summary>
        public static readonly DependencyProperty DetectResultColorProperty = DependencyProperty.Register("DetectResultColor", typeof(System.Drawing.Color), typeof(TargetDetectView), new FrameworkPropertyMetadata(System.Drawing.Color.White, FrameworkPropertyMetadataOptions.AffectsRender));

        /// <summary>
        /// 指标检测数据
        /// </summary>
        public MTargetDetectDto TargetDetectData { get { return (MTargetDetectDto)GetValue(TargetDetectDataProperty); } set { SetValue(TargetDetectDataProperty, value); } }
        /// <summary>
        /// 指标检测数据属性
        /// </summary>
        public static readonly DependencyProperty TargetDetectDataProperty = DependencyProperty.Register("TargetDetectData", typeof(MTargetDetectDto), typeof(TargetDetectView), new FrameworkPropertyMetadata(default, FrameworkPropertyMetadataOptions.AffectsRender));

        /// <summary>
        /// 构造函数
        /// </summary>
        public TargetDetectView()
        {
            InitializeComponent();
            ((FrameworkElement)this.Content).DataContext = this;
        }

        /// <summary>
        /// 开始渲染事件[重写]
        /// </summary>
        /// <param name="drawingContext"></param>
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            this.DetectBackgroundColor = new SolidColorBrush(ToMediaColor(this.DetectColor));
            this.DetectResultBackgroundColor = new SolidColorBrush(ToMediaColor(this.DetectResultColor));
        }

        /// <summary>
        /// 颜色转换
        /// </summary>
        /// <param name="drawingColor"></param>
        /// <returns></returns>
        protected Color ToMediaColor(System.Drawing.Color drawingColor)
        {
            return Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B);
        }
    }
}
